import { Schema as S } from "@triplit/client";

export const threadFormsSchema = {
  schema: S.Schema({
    id: S.Id({ format: "nanoid" }),
    threadId: S.String({
      nullable: true,
    }),
    chatInput: S.Optional(
      S.Record({
        text: S.String({ nullable: true }),
        attachments: S.Json({ nullable: true }),
      }),
    ),
    chatParameters: S.Optional(
      S.Record({
        temperature: S.Number({ nullable: true }),
        topP: S.Number({ nullable: true }),
        maxTokens: S.Number({ nullable: true }),
        presencePenalty: S.Number({ nullable: true }),
        frequencyPenalty: S.Number({ nullable: true }),
        numberOfHistoricalContext: S.Number({ nullable: true }),
        autoabstractContext: S.Boolean({ nullable: true }),
        abstractPrompt: S.String({ nullable: true }),
        systemPrompt: S.String({ nullable: true }),
        userPromptTemplate: S.String({ nullable: true }),
      }),
    ),
    systemPromptVariables: S.Optional(
      S.Set(
        S.String({
          enum: ["input", "date", "time", "datetime", "now", "model_id"],
        }),
      ),
    ),
    systemPromptRenderMap: S.Optional(S.Json()),
    systemPromptRenderedContent: S.Optional(S.String()),
    createdAt: S.Date({ default: S.Default.now() }),
    updatedAt: S.Date({ default: S.Default.now() }),
  }),
  relationships: {
    threads: S.RelationById("threads", "$threadId"),
  },
};
